package com.elysia.gateway.Config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration
public class CorsConfiguration {
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource source=new UrlBasedCorsConfigurationSource();
        org.springframework.web.cors.CorsConfiguration corsConfiguration=new org.springframework.web.cors.CorsConfiguration();

        //允许哪些请求头跨域
        corsConfiguration.addAllowedHeader("*");
        //允许哪些方法跨域
        corsConfiguration.addAllowedMethod("*");
        //允许哪些来源的请求跨域
        corsConfiguration.addAllowedOrigin("*");
        //允许请求包含cookie
        corsConfiguration.setAllowCredentials(true);

        source.registerCorsConfiguration("/**",corsConfiguration);
        return new CorsWebFilter(source);
    }
}
